package shapes.shapes2D 
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class Cross extends BaseShape
	{
		
		private var _rect:Rectangle;
		private var r0:Rectangle;
		private var r1:Rectangle;
		private var _thick_H:Number;
		private var _thick_V:Number;
		
		public function Cross( rect:Rectangle, thick_H:Number = -1, thick_V:Number = -1  ) 
		{
			
			_thick_H = thick_H == -1 ? rect.width / 3 : thick_H;
			
			_thick_V = thick_V == -1 ? rect.height / 3 : thick_V;
			
			_rect = rect.clone();
			
			this.x = rect.x - rect.width / 2;
			this.y = rect.y - rect.height / 2;
			
			resetRect();
			
		}
		
		public function draw( graphics:Graphics = null ):void
		{
			
			var ox:Number = x;
			var oy:Number = y;
			if ( graphics == null ) 
			{
				
				graphics = this.graphics;
				ox = oy = 0;
				graphics.lineStyle( strokeWidth, strokeColor, strokeAlpha );
				graphics.beginFill( fillColor, fillAlpha );
				graphics.drawRect( ox + r0.x, oy + r0.y, r0.width, r0.height );
				graphics.endFill();
				graphics.beginFill( fillColor, fillAlpha );
				graphics.drawRect( ox + r1.x, oy + r1.y, r1.width, r1.height );
				graphics.endFill();
				return;
			}
			
			graphics.drawRect( ox + r0.x, oy + r0.y, r0.width, r0.height );
			graphics.drawRect( ox + r1.x, oy + r1.y, r1.width, r1.height );
		}
		
		private function resetRect():void
		{
			
			var t:Point = new Point( 0, -rect.height / 2 );
			var l:Point = new Point( -rect.width / 2, 0 );
			
			r0 = new Rectangle( t.x - thick_H / 2, t.y, thick_H, rect.height );
			r1 = new Rectangle( l.x, l.y - thick_V / 2, rect.width, thick_V );
			
		}
		
		public function get rect():Rectangle { return _rect; }
		
		public function set rect(value:Rectangle):void 
		{
			_rect = value;
			resetRect();
		}
		
		public function get thick_H():Number { return _thick_H; }
		
		public function set thick_H(value:Number):void 
		{
			_thick_H = value;
			resetRect();
		}
		
		public function get thick_V():Number { return _thick_V; }
		
		public function set thick_V(value:Number):void 
		{
			_thick_V = value;
			resetRect();
		}
		
		
	}

}